﻿@model XRM.Security.WebUI.Models.Request.PrintFormModel
@{
    ViewBag.Title = "Выбор вида работ";
    Layout = "~/Views/Shared/_LayoutDialog.cshtml";
}

<div id="SelectWorkKindDialog">
    @if (Model.RequestWorkKind != null && Model.RequestWorkKind.Any())
    {
        <table class="table table-striped table-with-selection" id="WorkKindSearchTable">
            <thead>
                <tr>
                    <th>Выбор</th>
                    <th>Вид работы в заявке</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var wk in Model.RequestWorkKind)
                {
                    <tr>
                        <td class="text-center">
                            <input type="radio" name="WorkKindId" value=@wk.RequestWorkKindId>
                        </td>
                        <td>
                            @wk.WorkKind.WorkKindName
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    }
</div>

<div class="modal-footer">
    <button id="SelectWorkKind" class="btn btn-primary">Выбрать</button>
    <button type="button" class="btn btn-default" data-dismiss="modal">Отмена</button>
</div>

<script type="text/javascript">

    $("#WorkKindSearchTable tbody tr").on("click", function () {
        $("tr.active", $(this).closest('tbody')).removeClass("active");
        $(this).addClass("active");
        $(this).find("input[type='radio']").prop("checked", true);
    });

    $("#SelectWorkKind").click(function () {
        var selected = $("#WorkKindSearchTable tr.active");
        if (selected.length == 0) {
            alert("Выберите вид работы");
        } else {
            var wk = $(selected).find("input[type='radio']").val();
            window.location.href = '@Html.Raw(Url.Action("PrintRequest", "Request", new { requestId = Model.RequestId, type = Model.PrintFormType, requestWorkKindId = "wkId" }))'.replace('wkId', wk);
            $('#dlgSelectWorkKindDialogDialog').modal('hide');
        }
    });

</script>